package org.project.areader.activity;

import org.project.areader.view.adapter.DirectoryAdapter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

/**
 * 
 * @author robin
 * @date 2011-3-21
 * 
 */
public class DirectoryActivity extends BaseActivity implements OnItemClickListener
{

	private ListView listView;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		setContentView(R.layout.direct);

		listView = (ListView) findViewById(R.id.directlist);

		int[] id = new int[]
		{ R.string.direct_a_title, R.string.direct_b_title, R.string.direct_c_title, R.string.direct_d_title,
				R.string.direct_e_title, R.string.direct_f_title, R.string.direct_g_title, R.string.direct_h_title,
				R.string.direct_i_title, R.string.direct_j_title, R.string.direct_k_title, R.string.direct_l_title,
				R.string.direct_m_title, R.string.direct_n_title };
		int[] content = new int[]
		{ R.string.direct_a_content, R.string.direct_b_content, R.string.direct_c_content, R.string.direct_d_content,
				R.string.direct_e_content, R.string.direct_f_content, R.string.direct_g_content, R.string.direct_h_content,
				R.string.direct_i_content, R.string.direct_j_content, R.string.direct_k_content, R.string.direct_l_content,
				R.string.direct_m_content, R.string.direct_n_content };

		int[][] images = new int[][]
		{
		{ R.drawable.a01 },
		{ R.drawable.b01 },
		{},
		{ R.drawable.d01 },
		{},
		{ R.drawable.f01 },
		{ R.drawable.g01, R.drawable.g02 },
		{ R.drawable.h01, R.drawable.h02 },
		{ R.drawable.i01 },
		{ R.drawable.j01, R.drawable.j02 },
		{ R.drawable.k01, R.drawable.k02 },
		{},
		{},
		{ R.drawable.n01, R.drawable.n02 } };

		DirectoryAdapter apa = new DirectoryAdapter(this, id, content,images);
		listView.setAdapter(apa);
		listView.setOnItemClickListener(this);

		super.onCreate(savedInstanceState);
	}

	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
	{
		DirectoryAdapter adapter = (DirectoryAdapter) listView.getAdapter();
		int[][] id = adapter.getContent(arg2);
		
		int[]content = new int[] {id[0][0],id[1][0]};
		int[]image = id[2];
		
		Intent intent = new Intent(this, DetailActivity.class);
		intent.putExtra("CONTENT", content);
		intent.putExtra("IMAGES", image);
		
		startActivity(intent);
		DirectoryActivity.this.finish();
	}
}
